package com.kinyx.framework.image;

import java.awt.image.BufferedImage;
import java.io.File;

import org.junit.Test;

import com.kinyx.framework.file.KPathUtils;

public class KImageCropper_Tester_ {

	final BufferedImage image1 = KImageUtils.readBufferedImage(new File(KPathUtils.target() + "/test-classes/file/category/test1.jpg"));
	final BufferedImage image2 = KImageUtils.readBufferedImage(new File(KPathUtils.target() + "/test-classes/file/category/test2.jpg"));
	final BufferedImage image3 = KImageUtils.readBufferedImage(new File(KPathUtils.target() + "/test-classes/file/category/test3.jpg"));

	@Test
	public void zoom() {
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test1_zoom_128_100.jpg", KImageCropper.zoom(this.image1, 128, 100));
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test1_zoom_100_128.jpg", KImageCropper.zoom(this.image1, 100, 128));

		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test2_zoom_128_100.jpg", KImageCropper.zoom(this.image2, 128, 100));
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test2_zoom_100_128.jpg", KImageCropper.zoom(this.image2, 100, 128));

		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test3_zoom_128_100.jpg", KImageCropper.zoom(this.image3, 128, 100));
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test3_zoom_100_128.jpg", KImageCropper.zoom(this.image3, 100, 128));
	}

	@Test
	public void zoomDiscard() {
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test1_zoomDiscard_128_100.jpg", KImageCropper.zoomDiscard(this.image1, 128, 100));
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test1_zoomDiscard_100_128.jpg", KImageCropper.zoomDiscard(this.image1, 100, 128));

		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test2_zoomDiscard_128_100.jpg", KImageCropper.zoomDiscard(this.image2, 128, 100));
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test2_zoomDiscard_100_128.jpg", KImageCropper.zoomDiscard(this.image2, 100, 128));

		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test3_zoomDiscard_128_100.jpg", KImageCropper.zoomDiscard(this.image3, 128, 100));
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test3_zoomDiscard_100_128.jpg", KImageCropper.zoomDiscard(this.image3, 100, 128));
	}

	@Test
	public void cut() {
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test1_cut_0_0_32_32.jpg", KImageCropper.cut(this.image1, 0, 0, 32, 32));
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test1_cut_0_0_32_64.jpg", KImageCropper.cut(this.image1, 0, 0, 32, 64));
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test1_cut_0_0_64_32.jpg", KImageCropper.cut(this.image1, 0, 0, 64, 32));
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test1_cut_32_32_32_32.jpg", KImageCropper.cut(this.image1, 32, 32, 32, 32));
	}

	@Test
	public void crop() {
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test1_crop_上半截_256_128_0_0_256_128.jpg", KImageCropper.crop(this.image1, 256, 128, 0, 0, 256, 128));
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test1_crop_下半截_256_128_0_128_256_128.jpg", KImageCropper.crop(this.image1, 256, 128, 0, 128, 256, 128));
		KImageUtils.write(KPathUtils.target() + "/test-classes/file/category/test1_crop_全图_256_128_0_0_256_256.jpg", KImageCropper.crop(this.image1, 256, 128, 0, 0, 256, 256));
	}

}
